/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package bluetoothserver.dataStore;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;

/**
 *
 * @author phil
 */
public class SavedFileImporter {
    BufferedReader buf;
    
    public SavedFileImporter(String path){
        try{
            buf = new BufferedReader(new FileReader(path));
        }catch(IOException e){}
    }

    public ArrayList<Question> importQuestions(){
        ArrayList<Question> imports = new ArrayList<Question>();
        String s = "";
        try{
            //Checks file to see if there is a question present
            while((s = buf.readLine())!= null){
                Question q = new Question();
                q.setQuestion(s);
                
                //reads the question type from the file
                s = buf.readLine();
                q.setType(Integer.parseInt(s));

                //reads the questions correct answer from the file
                s = buf.readLine();
                q.setCorrectAnswer(Integer.parseInt(s));

                //reads all the stored answers from the file
                s = buf.readLine();
                q.setAnswers(s.split(","));

                //adds questions to the list and repeats
                imports.add(q);
            }
        }catch(IOException e){}
        try {
            buf.close();
        } catch (IOException ex) {}
        return imports;
    }
}
